<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>数据网格之选定 - jQuery EasyUI 演示</title>
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../demo.css">
	<script type="text/javascript" src="../../jquery.min.js"></script>
	<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
	<h2 title="DataGrid Selection">数据网格之选定</h2>
	<p title="Choose a selection mode and select one or more rows.">　　选择一个选中模式并点选一或多行。</p>
	<div style="margin:20px 0;">
		<a href="#" class="easyui-linkbutton" onclick="getSelected()">选了哪行？</a>
		<a href="#" class="easyui-linkbutton" onclick="getSelections()">选定了哪些行？</a>
	</div>
	<table id="dg" class="easyui-datagrid" title="<c>选定</c>" style="width:650px;height:280px"
			data-options="singleSelect:true,url:'datagrid_data1.json',method:'get'">
		<thead>
			<tr>
				<th data-options="field:'itemid',halign:'center'"><h title='Item ID'>物料编码</h></th>
				<th data-options="field:'productid',halign:'right'"><h title='Product ID'>品</h></th>
				<th data-options="field:'productname'"><h title='Product Name'>名</h></th>
				<th data-options="field:'listprice',align:'right',halign:'center'"><h title='List Price'>清单价格</h></th>
				<th data-options="field:'unitcost',align:'right',halign:'center'"><h title='Unit Cost'>成本单价</h></th>
				<th data-options="field:'attr1',halign:'center'"><h title='Attribute'>物料属性</h></th>
				<th data-options="field:'status',align:'center'"><h title='Status'>状态</h></th>
			</tr>
		</thead>
	</table>
	<div style="margin:10px 0;">
		<span title="Selection Mode: ">选定模式：</span>
		<select onchange="$('#dg').datagrid({singleSelect:(this.value==0)})">
			<option value="0" title="Single Row">仅单行</option>
			<option value="1" title="Multiple Rows">多行</option>
		</select>
	</div>
	<script type="text/javascript">
		function getSelected(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				$.messager.alert('<h title="Info">信息 …</h>', '物料编码：'+row.itemid+"<br/>产品编码："+row.productid+"<br/>物料属性："+row.attr1);
			}
		}
		function getSelections(){
			var ss = ['　物料编码｜产品编码｜物料属性'];
			var rows = $('#dg').datagrid('getSelections');
			for(var i=0; i<rows.length; i++){
				var row = rows[i];
				ss.push('<span>'+row.itemid+"｜"+row.productid+"｜"+row.attr1+'</span>');
			}
			$.messager.alert('<h title="Info">信息 …</h>', ss.join('<br/>'));
		}
	</script>
</body>
</html>